package com.sch.study.collection;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * User: hui_stone
 * Date: 2016/2/21 0021
 * Time: 下午 20:16
 */
public class ConcurrentHashMapTest {

    private static final Map<String,String> map = new ConcurrentHashMap<String,String>();

    private static void printAll(){
        for(Map.Entry<String,String> entry:map.entrySet()){
            System.out.print(entry.getKey() + " - " + entry.getValue() + ", ");
        }
        System.out.println();
    }
    static class MyThread extends Thread{

        MyThread(String name){
            super(name);
        }
        @Override
        public void run(){
            int i=0;
            while (i++<6){
                String val = Thread.currentThread().getName()+i;
                map.put(String.valueOf(i),val);
                printAll();
            }
        }
    }

    public static void main(String[] args) {

        new MyThread("ta").start();
        new MyThread("tb").start();
    }
}
